package com.geekaca.d4.d2_format;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

public class TestFormat {
    public static void main(String[] args) {
//        testDate();
        testTime();

    }

    public static void testTime() {
        /**
         * LocalTime;
         */
        LocalTime nowTime = LocalTime.now();
        System.out.println("当前时间: " + nowTime);
        int hour = nowTime.getHour();
        System.out.println("hour = " + hour);
        LocalTime timeMy = LocalTime.of(15, 52);
        System.out.println(timeMy);

        //LocalDateTime;
        LocalDateTime myTime1 = LocalDateTime.of(2023, 6, 20, 14, 12);
        System.out.println("mytime1: " + myTime1);


    }

    public static void testDate() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss S亳秒");
        String format = sdf.format(date);
        System.out.println(format);
        System.out.println(sdf.format(date));

        // 格式化时间戳
        long l = System.currentTimeMillis();
        l = +1245;
        String format1 = sdf.format(l);
        System.out.println("format1 " + format1);

        String formatStr3 = sdf.format(new Date());
        System.out.println(formatStr3);
    }
}
